/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lidroid.xutils_sample.slice;

import com.lidroid.xutils_sample.BitmapUtilsAbility;
import com.lidroid.xutils_sample.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.agp.components.Text;

public class MainAbilitySlice extends AbilitySlice {

    private String bundleName = "com.lidroid.xutils_sample";

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        Text btnDb=(Text)findComponentById(ResourceTable.Id_btn_db);
        Text btnView=(Text)findComponentById(ResourceTable.Id_btn_view);
        Text bitmapbuttpn= (Text) findComponentById(ResourceTable.Id_bitmaputils);
        bitmapbuttpn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent intent1=new Intent();
                Operation operation = new Intent.OperationBuilder()
                        .withBundleName(bundleName)
                        .withAbilityName(BitmapUtilsAbility.class)
                        .build();
                intent1.setOperation(operation);
                startAbility(intent1);
            }
        });
        Text btnHttp=(Text)findComponentById(ResourceTable.Id_btn_http);
        btnDb.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(bundleName)
                        .withAbilityName("com.lidroid.xutils_sample.DbUtilsPage")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);
            }
        });
        btnView.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(bundleName)
                        .withAbilityName("com.lidroid.xutils_sample.ViewUtilsPage")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);
            }
        });
        btnHttp.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(bundleName)
                        .withAbilityName("com.lidroid.xutils_sample.HttpUtilsPage")
                        .build();
                secondIntent.setOperation(operation);
                // 通过AbilitySlice的startAbility接口实现启动另一个页面
                startAbility(secondIntent);
            }
        });
    }
    @Override
    public void onActive() {
        super.onActive();

    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
/*private  void  reqP()
{
    if (verifySelfPermission("ohos.permission.CAMERA") != IBundleManager.PERMISSION_GRANTED) {
        // 应用未被授予权限
        if (canRequestPermission("ohos.permission.CAMERA")) {
            // 是否可以申请弹框授权(首次申请或者用户未选择禁止且不再提示)
            requestPermissionsFromUser(
                    new String[] { "ohos.permission.CAMERA" } , MY_PERMISSIONS_REQUEST_CAMERA);
        } else {
            // 显示应用需要权限的理由，提示用户进入设置授权
        }
    } else {
        // 权限已被授予
    }
}*/

}
